if ( window.onpopstate )
{
    window.onpopstate = function( event )
    {
        var state = event.state;

        if ( state && state["__id"] )
        {
            sendRepeaterRequest( state["__id"], window.location.href );
        }
    };
}

goog.events.listen( document.body, goog.events.EventType.CLICK, function( e )
{
    var el = (e).target;

    if ( el.tagName.toLowerCase() == 'a' && goog.dom.classes.has( el, "__repeater-link" ) )
    {
        if ( !el.getAttribute( "disabled" ) )
        {
            var containerId = el.getAttribute( "rid" );
            var uri = el.href;

            sendRepeaterRequest( containerId, uri );

            if ( history.pushState )
            {
                history.pushState( {"__id": containerId}, null, uri );
            }
        }

        e.preventDefault();
    }
} );

function sendRepeaterRequest( containerId, uri )
{
    var xhr = new goog.net.XhrIo();
    goog.events.listen( xhr, goog.net.EventType.SUCCESS, function( e )
    {
        var data = e.target.getResponse();
        var container = document.getElementById( containerId );
        goog.dom.replaceNode( goog.dom.htmlToDocumentFragment( data ), container );
    } );

    // set ajax header
    var headers = new goog.structs.Map();
    headers.set( "X-Requested-With", "XMLHttpRequest" );

    // send request
    xhr.send( uri, "GET", null, headers );
}